package com.yi.gostockgo.common.email;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author ：liandyao
 * @description：邮箱发送
 * @date ：2020/4/22 17:13
 */
@Component
public class JMailSend {

    @Resource
    JavaMailSender javaMailSender;


    Logger logger = LoggerFactory.getLogger(JMailSend.class);


    /**
     * 发送邮件
     * @param mailBean
     */
    public void sendSimpleMail(JMailBean mailBean) {
        try {
            SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
            //邮件发送人
            simpleMailMessage.setFrom(mailBean.getSender());
            //邮件接收人
            simpleMailMessage.setTo(mailBean.getRecipient());
            //邮件主题
            simpleMailMessage.setSubject(mailBean.getSubject());
            //邮件内容
            simpleMailMessage.setText(mailBean.getContent());
            javaMailSender.send(simpleMailMessage);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("邮件发送失败", e.getMessage());
        }
    }
}
